package com.h2.gwt.util.page;

import java.util.ArrayList;
import java.util.Collection;

import com.google.gwt.user.client.ui.Panel;
import com.h2.gwt.util.appstorage.UrlAppStorage;

public class PageRegistry {
   
   private UrlAppStorage _appStorage;
   
   private Collection<IPageListener> _pageListeners =
      new ArrayList<IPageListener>();
   
   private String _pageParamName;
   
   ////
   ////
   
   public void addPageListener(IPageListener listener) {
      getPageListeners().add(listener);
   }
   
   public void onChange(Panel panel) {
      String pageName = getAppStorage().get(getPageParamName());
      for (IPageListener listener : getPageListeners()) {
         listener.handle(panel, pageName);
      }
   }

   /**
    * @return the pageListeners
    */
   public Collection<IPageListener> getPageListeners() {
      return _pageListeners;
   }

   /**
    * @param pageListeners the pageListeners to set
    */
   public void setPageListeners(Collection<IPageListener> pageListeners) {
      _pageListeners = pageListeners;
   }

   /**
    * @return the appStorage
    */
   public UrlAppStorage getAppStorage() {
      return _appStorage;
   }

   /**
    * @param appStorage the appStorage to set
    */
   public void setAppStorage(UrlAppStorage appStorage) {
      _appStorage = appStorage;
   }

   /**
    * @return the pageParamName
    */
   public String getPageParamName() {
      return _pageParamName;
   }

   /**
    * @param pageParamName the pageParamName to set
    */
   public void setPageParamName(String pageParamName) {
      _pageParamName = pageParamName;
   }

}
